package org.liuyuantao.patterns.singleton;

/**
 * 这种方式同样利用了classloder的机制来保证初始化instance时只有一个线程
 */
public class Singleton02 {
    private static class SingletonHolder {
        private static final Singleton02 INSTANCE = new Singleton02();
    }

    private Singleton02() {
        System.out.println("创建了Singleton02实例!");
    }

    public static final Singleton02 getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public void whoAmI() {
        System.out.println(this.toString());
    }
}  